<template>
  <div>
    <a-card class="card" title="基本信息" :bordered="false">
      <base-info-form ref="baseInfo" :showSubmit="false" />
    </a-card>
    <a-card class="card" title="商店信息" :bordered="false">
      <goods-info-form ref="goodsInfo" :showSubmit="false" />
    </a-card>

    <!-- table -->
    <div>
      <a-button size="large" @click="close()" type="danger" style="float : left">关闭</a-button>
    </div>
    <!-- fixed footer toolbar -->
    <footer-tool-bar>
      <a-button type="primary" @click="validate" :loading="loading">提交</a-button>
    </footer-tool-bar>
  </div>
</template>
<script>
import FooterToolBar from '@/components/tools/FooterToolBar'
// import BaseInfoFom from './BaseInfoFom'
import moment from 'moment'
// import GoodsInfoForm from './GoodsInfo'
import { log } from 'util'
import { filterObj } from '@/utils/util'
import { httpAction, getAction } from '@/api/manage'
export default {
  name: 'TemplateAdvancedForm',
  components: {
    FooterToolBar,
    // 'base-info-form': BaseInfoFom,
    // 'goods-info-form': GoodsInfoForm
  },
  data() {
    return {
      description: '高级表单常见于一次性输入和提交大批量数据的场景。',
      loading: false,
      data: {},
      validatorRules: {
        //修改
        name: {
          rules: [
            //rules是验证规则，
            {
              required: true, //是否为必填，否则将会出现提示信息
              message: '请输入团名称' //当输入框为空时，呈现出的提示信息
            },
            {
              validator: this.checkName //自定义的校验函数
            }
          ]
        }
        //修改
      }
    }
  },
  onactived() {
    this.$refs.baseInfo.form.resetFields()
    this.$refs.goodsInfo.form.resetFields()
  },
  methods: {  
    handleSubmit(e) {
      e.preventDefault()
    },
    close() {
      this.$router.replace({ path: '/promotion' })
    },
    // 最终全页面提交
    validate() {
      console.log('212312')
      debugger
      const that = this
      this.loading = true
      this.$refs.baseInfo.form.validateFields((err, values) => {
        if (!err) {
          console.log('212312')
          enableSubmit1 = true
        } else {
          return
        }
      })
      this.$refs.goodsInfo.form.validateFields((err, values) => {
        console.log(err)
        if (!err) {
        } else {
          return
        }
      })
      this.data = {
        ...this.$refs.baseInfo.form.getFieldsValue().couponTemplate,
        ...this.$refs.goodsInfo.form.getFieldsValue().couponTemplate
      }
      if (this.data.rangeValues != null || this.data.rangeValues != undefined) {
        this.data.rangeValues = this.data.rangeValues.join()
      }
      this.data.priceAvailable = this.data.priceAvailable * 100
      this.data.discountPriceLimit = this.data.discountPriceLimit * 100

      this.data.priceOff = this.data.priceOff * 100

      this.data.validStartTime = moment(this.data.validStartTime)
          .format('YYYY-MM-DD HH:mm:ss')
        this.data.validEndTime = moment(this.data.validEndTime)
          .format('YYYY-MM-DD HH:mm:ss')
      httpAction('/admins/coupon/template/addCard', this.data, 'post')
        .then(res => {
          if (res.success) {
            that.$message.success(res.message)
            that.$emit('ok')
            that.$router.back()
          } else {
            that.$message.warning(res.message)
          }
        })
        .finally(() => {
          that.loading = false
        })
    }
  }
}
</script>

<style lang="scss" scoped>
.card {
  margin-bottom: 24px;
}
</style>
